<style>
<!--
#quoteform{
	width: 931px;
	height: 152px;
	padding: 20px;
}
.zend_form dt {
	width: 62px !important;
}
#bottom_button{
	height: 28px;
	line-height: 28px;
	text-align: right;
	padding: 11px;
}
-->
</style>
<div class="flexigrid ui-datepicker ui-widget ui-widget-content  ui-corner-all" id="accountsList" style="width: 99%; display: block;">
	<div class="mDiv ui-datepicker-header ui-widget-header  ui-corner-all">
		<div class="ftitle">修改报价单</div>
		<div class="ptogtitle" title="Minimize/Maximize Table"><span></span></div>
	</div>
	<div id="quoteform">
	<?php echo $this->form;?>
	</div>
	<table id="quotelist"></table>
	<div id="bottom_button">
		<button>预览</button>
		<button onClick="sub(event)">保存</button>
		<button>保存并发送</button>
		<button>删除</button>
	</div>
</div>
<script><!--
$(function() {
	//时间
	$("#enquiry_time,#quoted_time_limit,#quoted_time,#remind_alarm_time").datepicker( $.datepicker.regional[ "zh-CN" ] );

	//按钮
	$("button").button();
	quoteid = $("#id").val();
	
	window.grids = $("#quotelist").flexigrid({
		url: '<?php echo $this->pagePath;?>/quote/listproduct/quoteid/'+quoteid,
		dataType: 'json',
		colModel : [
			{display: 'ID', name : 'id', width : 20, sortable : true, align: 'center'},
			//{display: '编号', name : 'code', width : 80, sortable : false, align: 'left'},
			//{display: '条形码', name : 'barcode', width : 80, sortable : true, align: 'left'},
			//{display: '名称', name : 'name_cn', width : 80, sortable : true, align: 'left'},
			{display: '英文名称', name : 'name_en', width : 80, sortable : true, align: 'left'},
			//{display: '供货商', name : 'factory', width : 80, sortable : true, align: 'left'},
			{display: '规格', name : 'specification', width : 80, sortable : true, align: 'left'},
			//{display: '图片', name : 'picture', width : 80, sortable : true, align: 'left'},			
			{display: '成本', name : 'cost', width : 80, sortable : false, align: 'left',process:gridHelper.Cash},
			{display: '售价', name : 'price', width : 80, sortable : true, align: 'left',process:gridHelper.Cash}//,
			//{display: '创建时间', name : 'create_time', width : 80, sortable : true, align: 'left'},
			//{display: '创建人', name : 'create_user', width : 80, sortable : true, align: 'left'},
			//{display: '备注', name : 'note', width : 80, sortable : true, align: 'left', hide: true}
			
		],
		searchitems : [
            {display: '名称' ,name : 'name_cn', isdefault: true},	                     		
			{display: '编号' ,name : 'code'},	                     		
			{display: '供货商' ,name : 'factory'}	
		],
		buttons : [
			<?php if($this->allow('add','user','')){?>
			{name: '新增',bclass:"add", onpress : add},
			<?php } ?>
			<?php if($this->allow('edit','user','')){?>
			{name: '编辑',bclass:"edit", onpress : edit},
			<?php } ?>
			<?php if($this->allow('delete','user','')){?>
			{name: '删除',bclass:"delete", onpress : del},
			<?php } ?>
			/*{name: '编辑权限', onpress : edit_right},*/
			{separator: true}
		], 
		sortname: "id",
		sortorder: "asc",
		novstripe:true,
		//singleSelect:true,//是否单选
		usepager: false,
		hideOnSubmit:false,//禁用遮照
		useRp: true,
		rp: 15,
		showTableToggleBtn: false,
		id:"accountsList",
		width: "99%",
		height: 218,
		onRowClick:function($e){
		},
		onRowDblclick:function(){
			//hideList();
		}
	}).show();
});

var
add = function(name,e){
	var top = $(this).offset().top;
	zendform.zendFormCreat(e,{
		url:"<?php echo $this->pagePath;?>/quote/addproduct/quoteid/"+quoteid,
		dialog:{
			title:"新增产品",
			width:505,
			height:300,
			position:[null,top]
		}
	});
}
,edit = function(name,e){
	id = $(e).find(".trSelected")[0].id.toString().replace("row","") || "0";
	var top = $(this).offset().top;
	zendform.zendFormCreat(e,{
		url:"<?php echo $this->pagePath;?>/quote/editproduct/id/"+(id),
		dialog:{
			title:"修改产品",
			width:505,
			height:300,
			position:[null,top]
		}
	});
}
,del = function(name,e){
	var ids = $(e).find(".trSelected");
	var idsData = [];
	$.each(ids,function(i,n){
		var uid = n.id.toString().replace("row","") || "0";
		uid = uid;
		idsData.push(uid);
	});
	if(confirm("您确定要删除这"+ids.length+"项数据吗？")){
		$.ajax({
			"url":"<?php echo $this->pagePath;?>/quote/del",
			"data":{id:idsData},
			"type":"POST",
			"success":function(data){
				if(data.status > 0){
					var randId = "id_" + Date.parse(new Date());
		        	window.grids.flexReload();
		        	$("<div id='"+randId+"'>"+data.msg+"</div>").dialog({title:"SUCCESS!",height: 140,modal: true});
		        	window.setTimeout(function(){$("#"+randId).dialog("close");},1200);
		        }else{
			        $("<div>ERROR!"+data.msg+"</div>").dialog({title:"ERROR!",height: 140,modal: true});
		        }
			},
			"error":function(){
		    	$("<div>ERROR!<br>服务错误！可能是网络忙！</div>").dialog({title:"ERROR!",height: 140,modal: true});
			}
		});
	}
}
,sub = function(event){
	event = event || window.event;
	var buttonT = $(event.target);
	buttonT.html("正在提交表单...").parent("button").attr({"disabled":"disabled"});
	//查找form
	var Did = "Did_" + Date.parse(new Date());
	var formT = $("#quoteform form");
	formT = formT || $(this).find("form");
	
	var reStr = formT.formSerialize ? formT.formSerialize() : formT.serialize();
	$.ajax({
		url: formT.attr("action"),
		data:reStr,
		dataType:"json",
		type:formT.attr("method") || "POST",
		success:function(data) {
			if (data.status == 1) {
				$("<div id='"+Did+"'>成功!"+data.msg+"</div>").dialog({title:"ERROR!",height: 140,modal: true});
				buttonT.html("保存");
				if(grids){
					window.setTimeout(function(){$("#"+Did).dialog("close");},1200);
				}
			}else{
				$("#quoteform").html(data['form']);
				$("<div>ERROR!"+data.msg+"</div>").dialog({title:"ERROR!",height: 140,modal: true});
				$("#enquiry_time,#quoted_time_limit,#quoted_time,#remind_alarm_time").datepicker( $.datepicker.regional[ "zh-CN" ] );
			}
			buttonT.html("保存").parent("button").attr({"disabled":false});
		},
		error:function(){
			$("<div>ERROR!<br>服务错误！可能是网络忙！</div>").dialog({title:"ERROR!",height: 140,modal: true});
			buttonT.html("保存").parent("button").attr({"disabled":false});
			$("#enquiry_time,#quoted_time_limit,#quoted_time,#remind_alarm_time").datepicker( $.datepicker.regional[ "zh-CN" ] );
		}
	});
}
--></script>